<template>
  <el-dialog title="Sign In" :visible="noToken" width="400px">
    <el-form :model="form" :rules="rules" ref="sign-in-form">
      <el-form-item label="账号" prop="id">
        <el-input v-model="form.id" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input @keydown.enter.native="handleSignIn" min="8" v-model="form.password" type="password" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <!-- <el-button type="primary" @click="signIn({id: '1601050807', password: 'helloworld'})" :circle="loading" :loading="loading">测试账号登陆</el-button> -->
      <el-button type="primary" @click="handleSignIn" :circle="loading" :loading="loading">{{loading ? "" : "确定"}}</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      loading: false,
      form: {
        id: "",
        password: ""
      },
      rules: {
        id: [
          { required: true, message: "请输入账号", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
        ]
      }
    };
  },
  mounted() {
  },
  computed: {
    ...mapGetters([
      "noToken",
      "accessToken"
    ])
  },
  methods: {
    ...mapActions([
      "signIn"
    ]),
    // 封装一层处理加载动画，
    async handleSignIn() {
      this.loading = true;
      let result = false;
      this.$refs["sign-in-form"].validate(valid => result = valid);
      if (result) {
        try {
          await this.signIn(this.form);
        } catch (error) {

        }
      }


      this.loading = false;
    }
  }
};
</script>

<style>
</style>
